<?php
namespace App\Http\Controllers\Item\Fxotary\Admin;

use App\Service\Item\Fxotary\Admin\YewuService;
use Illuminate\Http\Request;

class YewuController extends BaseController
{
    //项目菜单

    public function __construct(YewuService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        $menu_id = $request->post('menu_id', 0); //1前台，2后
        $res = $this->db->getIndex($menu_id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //一个
    public function getOne(Request $request)
    {
        $id = $request->post('id');
        $res = $this->db->getOne($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id');
        $val = $request->post('val', '');
        if (!$val) {
            return $this->toJson(-2, '字段值必须的');
        }
        $res = $this->db->modify($id, $val);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0);
    }
}